package com.yxhl.zoume.core.user.presenter.mywallet;

import android.content.Context;

import com.yxhl.zoume.common.presenter.BasePresenter;
import com.yxhl.zoume.common.presenter.IPresenter;
import com.yxhl.zoume.common.ui.view.BaseView;
import com.yxhl.zoume.core.user.view.TradeRecordDetailView;
import com.yxhl.zoume.data.http.model.mywallet.TradeRecordDetailBean;
import com.yxhl.zoume.data.http.rest.param.mywallet.TradeRecordDetailParam;
import com.yxhl.zoume.data.http.rest.response.mywallet.TradeRecordDetailResponse;
import com.yxhl.zoume.domain.interactor.ZMSubscriber;
import com.yxhl.zoume.domain.interactor.mywallet.TradeRecordDetailUseCase;

import javax.inject.Inject;

/**
 * 项目名称：Ferrari
 * Created by menggod on 16/11/17 .
 */

public class TradeRecordDetailPresenter extends BasePresenter implements IPresenter {


    TradeRecordDetailView mTradeRecordDetailView;
    @Inject
    TradeRecordDetailUseCase  mTradeRecordDetailUseCase;

    @Inject
    public TradeRecordDetailPresenter(Context context) {
        super(context);
    }

    public void queryTradeRecordDetail(String orderId){

        TradeRecordDetailParam tradeRecordDetailParam = new TradeRecordDetailParam(orderId);
        tradeRecordDetailParam
                .setMobile(getMobile())
                .setToken(getToken());

        mTradeRecordDetailUseCase.execute(tradeRecordDetailParam,new ZMSubscriber<TradeRecordDetailResponse>(){
                    @Override
                    public void onCompleted() {
                        super.onCompleted();
                    }

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                    }

                    @Override
                    public void onNext(TradeRecordDetailResponse tradeRecordDetailResponse) {
                        super.onNext(tradeRecordDetailResponse);
                        if (null != tradeRecordDetailResponse){
                            boolean isSuccess = tradeRecordDetailResponse.isSucc();
                            if (isSuccess){
                                TradeRecordDetailBean tradeRecordDetail = tradeRecordDetailResponse.getTradeRecordDetail();
                                mTradeRecordDetailView.renderTradeRecordDetailOnSuccess(tradeRecordDetail);
                            }else{

                            }
                        }
                    }
                });


    }

    @Override
    public void attachView(BaseView view) {
        mTradeRecordDetailView = (TradeRecordDetailView) view;

    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        mTradeRecordDetailUseCase.unsubscribe();
    }
}
